//
// Created by overlord on 18-4-6.
//
#include <jni.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <android/log.h>
#define LOG_TAG  "TAG"
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)

jint Java_com_sat_ndk_JNI_Add(JNIEnv *env, jobject instance, jint x, jint y) {

    return x+y;

}

jstring Java_com_sat_ndk_JNI_ChangeStr(JNIEnv *env, jobject instance, jstring str_) {
    char *str = (*env)->GetStringUTFChars(env, str_, 0);
//    int length = (*env)->GetStringUTFLength

    int length = strlen(str);
    for (int i = 0; i < length; ++i) {
        *(str+i) +=1;
    }

    (*env)->ReleaseStringUTFChars(env, str_, str);

    return (*env)->NewStringUTF(env, str);
}

JNIEXPORT jintArray JNICALL
Java_com_sat_ndk_JNI_arrIncrease(JNIEnv *env, jobject instance, jintArray array_) {
    jint *array = (*env)->GetIntArrayElements(env, array_, NULL);

    //    jsize       (*GetArrayLength)(JNIEnv*, jarray);
    jsize length = (*env)->GetArrayLength(env, array_);
    //jint*       (*GetIntArrayElements)(JNIEnv*, jintArray, jboolean*);
    for (int i = 0; i < length; ++i) {
        LOGD("原来的数是%d",*(array+i));
        *(array+i)+=10;
    }
    (*env)->ReleaseIntArrayElements(env, array_, array, 0);
    return array_;
}